package gui;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;

import javax.swing.*;
import javax.swing.event.*;

import components.register.RegisterGroup;

public class SelectButton extends JButton {
	public ImageIcon icon1;
	public boolean isSelected;
	public static SelectButton preButton;
	int num;

	private static RegisterGroup regl = RegisterGroup.getInstance();

	public SelectButton() {
		isSelected = false;

		URL url1 = TestMain.class.getResource(TestMain.imgDir + "select.png");

		icon1 = new ImageIcon(url1);

		this.setIcon(icon1);
		this.setContentAreaFilled(false);
		this.setBorder(null);
		this.setOpaque(false);
		this.preButton = null;

		this.addMouseListener(new MouseListener() {

			@Override
			public void mouseClicked(MouseEvent e) {

				RegisterLightGroup reglg[] = { ControlPanel.PC_Light,
						ControlPanel.MAR_Light, ControlPanel.MBR_Light,
						ControlPanel.IR_Light, ControlPanel.CC_Light,
						ControlPanel.OR_Light, ControlPanel.ADDR_Light,
						ControlPanel.MFR_Light, ControlPanel.MSR_Light,
						ControlPanel.R1_Light, ControlPanel.R2_Light,
						ControlPanel.R3_Light, ControlPanel.R4_Light,
						ControlPanel.RAR1_Light, ControlPanel.RAR2_Light,
						ControlPanel.DEVR_Light };
				if (HaltButton.isOn == true) {
					if (preButton != null) {
						preButton.setBorder(null);
						preButton.isSelected = false;
						reglg[preButton.num].editable = false;
						reglg[preButton.num].refresh();
					}
					setBorder(BorderFactory.createLineBorder(Color.green));
					preButton = (SelectButton) e.getComponent();
					isSelected = true;
					reglg[num].editable = true;
					reglg[num].refresh();
				}
			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
			}

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
			}

			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
			}

		});
	}
}
